/* eslint-disable */
const fs = require('node:fs')
const path = require('node:path')
const date = new Date()
const prefix =`${process.env.CI_PROJECT_NAME}/${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}/`

const config = {
  src_dir: path.resolve('dist').replace(/\\/g, '/'),
  bucket: '',
  key_prefix: '',
  up_host: 'http://up-z2.qiniup.com',
  overwrite: true,
  skip_fixed_strings: '.svn,.git',
  skip_suffixes: '.DS_Store,.exe',
  log_stdout: true
}

const deployEnv = process.env.DREAMENV
let bucketStr = ''
switch (deployEnv) {
  case 'TEST':
    bucketStr = process.env.QINIU_TEST
    break
  case 'PROD':
    bucketStr = process.env.QINIU_PROD
    break
}
if (!bucketStr) {
  throw new Error('config get error')
}
const bucketConfig = JSON.parse(bucketStr)
config.bucket = bucketConfig.bucket
config.key_prefix = prefix
fs.writeFileSync('qiniuconfig', JSON.stringify(config))
